package com.example.framework.security.config;

import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer;

/**
 * 框架模块的bean也需要在spi中导出
 */
public class AuthorizeRequestsCustomizer implements Customizer<AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry> {
    @Override
    public void customize(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry authorizationManagerRequestMatcherRegistry) {
        // Swagger 接口文档
        authorizationManagerRequestMatcherRegistry.requestMatchers("/v3/api-docs/**").permitAll()
                .requestMatchers("/webjars/**").permitAll()
                .requestMatchers("/swagger-ui.html").permitAll()
                .requestMatchers("/swagger-ui/**").permitAll()
                .requestMatchers("/favicon.ico").permitAll();
        // Spring Boot Actuator 的安全配置
        authorizationManagerRequestMatcherRegistry.requestMatchers("/actuator").permitAll()
                .requestMatchers("/actuator/**").permitAll();
        // Druid 监控
        authorizationManagerRequestMatcherRegistry.requestMatchers("/druid/**").permitAll();
        // Spring MVC 错误
        authorizationManagerRequestMatcherRegistry.requestMatchers("/error/**").permitAll();
    }
}
